//
//  GFHeader.m
//  Qyer
//
//  Created by dlios on 15/10/23.
//  Copyright (c) 2015年 GF. All rights reserved.
//

#import "GFHeader.h"

@implementation GFHeader

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        _image = [[UIImageView alloc] initWithFrame:CGRectMake(5 * WIDTH, 5 * WIDTH, SCREEN_WIDTH - 10 * WIDTH, 180 * HEIGHT)];
        [self addSubview:_image];
        
        _titleLable = [[UILabel alloc] initWithFrame:CGRectMake(5 * WIDTH, 5 * HEIGHT, SCREEN_WIDTH - 20 * WIDTH, 20 * HEIGHT)];
        [_titleLable setFont:[UIFont boldSystemFontOfSize:WIDTH * 16.]];
        [_titleLable setTextColor:[NightMode shareNightModeHandle].wordColor];
        [_image addSubview:_titleLable];
        
        _timeLable = [[UILabel alloc] initWithFrame:CGRectMake(5 * WIDTH, 25 * HEIGHT, SCREEN_WIDTH - 20 * WIDTH, 20 * HEIGHT)];
        [_timeLable setFont:[UIFont systemFontOfSize:WIDTH * 14.]];
        [_timeLable setTextColor:[NightMode shareNightModeHandle].grayWordColor];
        [_image addSubview:_timeLable];
        
        _userImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        [_image addSubview:_userImage];
        
        _userLable = [[UILabel alloc] initWithFrame:CGRectZero];
        [_userLable setTextColor:[NightMode shareNightModeHandle].wordColor];
        [_userLable setFont:[UIFont systemFontOfSize:WIDTH * 14.]];
        [_image addSubview:_userLable];
        
        _desLable = [[UILabel alloc] initWithFrame:CGRectZero];
        [_desLable setTextColor:[NightMode shareNightModeHandle].wordColor];
        [_desLable setFont:[UIFont systemFontOfSize:WIDTH * 14.]];
        [_desLable setNumberOfLines:0];
        [self addSubview:_desLable];
    }
    return self;
}

- (void)gettitleString:(NSString *)title time:(NSString *)time bigImage:(NSString *)image userImage:(NSDictionary *)userDic{
    [_image sd_setImageWithURL:[NSURL URLWithString:image] placeholderImage:[UIImage imageNamed:@"zw.png"]];
    [_titleLable setText:title];
    [_timeLable setText:time];
    if (userDic != nil) {
        [_userImage setFrame:CGRectMake(5 * WIDTH, 135 * HEIGHT, 40 * WIDTH, 40 * HEIGHT)];
        [_userImage sd_setImageWithURL:[NSURL URLWithString:[userDic objectForKey:@"image"]] placeholderImage:[UIImage imageNamed:@"zw.png"]];
        [_userLable setFrame:CGRectMake(50 * WIDTH, 135 * HEIGHT, SCREEN_WIDTH - 55 * WIDTH, 40 * HEIGHT)];
        [_userLable setText:[userDic objectForKey:@"name"]];
        [_desLable setFrame:CGRectMake(0, 0, 0, 0)];
    }else{
        [_userImage setFrame:CGRectMake(0, 0, 0, 0)];
        [_userLable setFrame:CGRectMake(0, 0, 0, 0)];
        [_desLable setFrame:CGRectMake(5 * WIDTH, 140 * HEIGHT, SCREEN_WIDTH - 20 *WIDTH, 40 * HEIGHT)];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
